import 'package:flutter/cupertino.dart';
import 'package:json_annotation/json_annotation.dart';

part 'delivery_setting_data.g.dart';

@JsonSerializable()
class DeliverySettingData extends Object {
  @JsonKey(name: 'freeDelivery')
  int freeDelivery;

  @JsonKey(name: 'freeDeliveryAmount')
  int freeDeliveryAmount;

  @JsonKey(name: 'settingId')
  int settingId;

  @JsonKey(name: 'takeoutCostSettingFormList', defaultValue: [])
  List<TakeoutCostSettingFormList> takeoutCostSettingFormList;

  bool get isFreeDelivery => freeDelivery == 1;

  DeliverySettingData(
    this.freeDelivery,
    this.freeDeliveryAmount,
    this.settingId,
    this.takeoutCostSettingFormList,
  );

  factory DeliverySettingData.fromJson(Map<String, dynamic> srcJson) => _$DeliverySettingDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$DeliverySettingDataToJson(this);
}

@JsonSerializable()
class TakeoutCostSettingFormList extends Object {
  @JsonKey(ignore: true)
  GlobalKey key;

  @JsonKey(name: 'costAmount')
  int costAmount;

  @JsonKey(name: 'targetValue')
  int targetValue;

  TakeoutCostSettingFormList(
    this.costAmount,
    this.targetValue,
  ) : key = GlobalKey();

  factory TakeoutCostSettingFormList.fromJson(Map<String, dynamic> srcJson) => _$TakeoutCostSettingFormListFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TakeoutCostSettingFormListToJson(this);
}
